package com.carbon.carbonmanager.controller;

import com.carbon.carbonmanager.model.TradeOrderInfo;
import com.carbon.carbonmanager.service.TradeService;
import com.carbon.carbonmanager.unit.Pager;
import com.carbon.carbonmanager.unit.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 订单交易模块API
 *
 * */
@RestController
@CrossOrigin
public class TradeController {
    @Autowired
    TradeService tradeService;

    /**
     * 发布交易（包括购买和售卖）API
     *
     * */
    @ResponseBody
    @RequestMapping(value = "/publishTradeOrder", method = RequestMethod.POST, produces = "application/json; utf-8")
    public Response publishTradeOrder(@RequestBody TradeOrderInfo tradeOrderInfo){
        return tradeService.publishTradeOrder(tradeOrderInfo);
    }

    /**
     * 管理碳信用资产
     * 发布人根据自身id查询自己的订单列表分页数据
     * */
    @ResponseBody
    @RequestMapping(value = "/getTradeOrderDataByPublishId", method = RequestMethod.POST, produces = "application/json; utf-8")
    public Response getTradeOrderDataByPublishId(@RequestBody Pager pager){
        return tradeService.getTradeOrderDataByPublishId(pager);
    }

    /**
     * 确认发布订单
     * 修改订单状态前进行验证
     * */
    @ResponseBody
    @RequestMapping(value = "/applyTradeOrder", method = RequestMethod.POST, produces = "application/json; utf-8")
    public Response applyTradeOrder(@RequestBody TradeOrderInfo tradeOrderInfo){
        return tradeService.applyTradeOrder(tradeOrderInfo);
    }


    /**
     * 确认撤销订单
     * 修改订单状态前进行验证
     * */
    @ResponseBody
    @RequestMapping(value = "/cancelTradeOrder", method = RequestMethod.POST, produces = "application/json; utf-8")
    public Response cancelTradeOrder(@RequestBody TradeOrderInfo tradeOrderInfo){
        return tradeService.cancelTradeOrder(tradeOrderInfo);
    }

    /**
     * 交易市场信息列表分页数据
     * 分页数据
     * */
    @ResponseBody
    @RequestMapping(value = "/getTradeMarketPagerData", method = RequestMethod.POST, produces = "application/json; utf-8")
    public Response getTradeMarketPagerData(@RequestBody Pager pager){
        return tradeService.getTradeMarketPagerData(pager);
    }

    /**
     * 交易市场：交易买入
     * */
    @ResponseBody
    @RequestMapping(value = "/tradeBuyOrder", method = RequestMethod.POST, produces = "application/json; utf-8")
    public Response tradeBuyOrder(@RequestBody TradeOrderInfo tradeOrderInfo){
        return tradeService.tradeBuyOrder(tradeOrderInfo);
    }

    /**
     * 交易市场：交易卖出
     * */
    @ResponseBody
    @RequestMapping(value = "/tradeSellOrder", method = RequestMethod.POST, produces = "application/json; utf-8")
    public Response tradeSellOrder(@RequestBody TradeOrderInfo tradeOrderInfo){
        return tradeService.tradeSellOrder(tradeOrderInfo);
    }

    /**
     * 根据用户id获取其自身购买或者售卖的日志信息
     * getTradeRecordDataByCurrentUser
     * */
    @ResponseBody
    @RequestMapping(value = "/getTradeRecordDataByCurrentUser", method = RequestMethod.POST, produces = "application/json; utf-8")
    public Response getTradeRecordDataByCurrentUser(@RequestBody Pager pager){
        System.out.println(pager);
        return tradeService.getTradeRecordDataByCurrentUser(pager);
    }
}
